<template>
	<view class="content">
		<scroll-view scroll-x class="tabs-content" enable-flex scroll-with-animation>
			<view class="order-nav">
				<view class="nav-item" v-for="(nav, index) in orderState"  :key="index"
					@tap="onNav(index, nav.id)">
					<view class="item-title" :class="{ 'item-title-active': tabindex === index }">{{ nav.title }}</view>
					<view class="nav-line" :class="{ 'line-active': tabindex === index }"></view>
				</view>
			</view>
		</scroll-view>
			<mescroll-body ref="mescrollRef" height="1050" @init="mescrollInit" @down="downCallback" @up="upCallback">
		<view class="team-list">
			<view class="team-item" v-for="(item, index) in resultList" :key="index">
				<view class="user-left">
					<image :src="item.avatar" ></image>
					<view class="user-detail">
						<view class="name">{{item.nickname}}</view>
						<view class="time">加入时间：{{item.createtime}}</view>
					</view>
				</view>
				<view class="user-right">
					<view class="row1"><text style="color: #F57F1F; margin-right: 10upx;">{{item.team_total}}</text>人</view>
					<view class="row2"><text style="margin-right: 10upx;">{{item.child_order_total}}</text> 单</view>
					<view class="row3"><text style="margin-right: 10upx;">{{item.team_order_money}}</text>元</view>
				</view>
			</view>
			<view style="width: 750upx;height: 1upx;background: #D2D2D2;"></view>
		</view>
		</mescroll-body>
	</view>
</template>

<script>
	import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
	export default {
		mixins: [MescrollMixin],
		data() {
			return {
				tabindex: 0,
				orderState: [{
						id: 1,
						title: '一级团队',
					},
					{
						id: 2,
						title: '二级团队'
					},
					],
					prams: {
						relationLevel: 1,
						page: 1,
						i:4,
						type:2,
						route:"member.member.getMyAgentData_v2",
						ingress:"weChatApplet",
						relationLevel:1,
						page:1,
						keyword:'',
						level:"",
						current_page:1,
						last_page: "",
						validate_page:1,
						app_type:"wechat",
					},
					resultList: [],
					
			};
		},
		onShow(){
			this.getteamSum();
		},
		methods: {
			onNav( index, id) {
				if (this.tabindex !== index) {
					this.tabindex = index;
					this.prams.relationLevel = id;
					this.downCallback();
					}
			},
			// 下拉刷新列表
			downCallback() {
				this.mescroll.resetUpScroll(); // 重置列表为第一页 (自动执行 page.num=1, 再触发upCallback方法 )
				// this.getteamSum();
			},
			/*上拉加载的回调*/
			upCallback(page) {
				this.prams.page = page.num;
				this.$http.get('user.teamlist', this.prams).then(res => {
					
					let curPageData = res.data.data;
					
					let curPageLen = curPageData.length;
					let totalCount = res.data.total;
					if (page.num == 1) this.resultList = []; //如果是第一页需手动置空列表
					this.resultList = this.resultList.concat(curPageData); //追加新数据
					this.mescroll.endBySize(curPageLen, totalCount);
				})
			},
			// 获取团队人数
			getteamSum(){
				this.$http.get('user.teamsum').then(res => {
					this.$set(this.orderState, '0', {
						id: 1,
						title: `一级团队(${res.data.my_agent.level1.total})`,
					})
					this.$set(this.orderState, '1', {
						id: 2,
						title: `二级团队(${res.data.my_agent.level2.total})`,
					})
				});
			}
		}
	}
</script>

<style scoped lang="scss">
	@import './my-team.scss';
</style>
